package main

import (
	"fmt"
	"context"
	"time"
)

type Interf interface{

	start()
}

type Bucket struct{
     Interf
     LinNum int
     LongTime time.Duration
     KeYong int 

}


func (l *Bucket)Get(){


}

func (l *Bucket)TakeAvailable() int{

        if l.KeYong > 0 {
	   l.KeYong--	
	   return 1
        }else {
           l.KeYong=0
	   return 0
        }
}


func (l *Bucket)Start(){

	go func(){

           for {
                select {
		   case  <- time.After(l.LongTime) :
			   l.KeYong++
			   fmt.Println("add keyong")
			   if l.KeYong > l.LinNum {
                               l.KeYong = l.LinNum
			   }

		}

	   }

	}()


}


func main(){

  ctx,onCansel := context.WithTimeout(context.Background() ,time.Second*10)
  defer onCansel()

  
  go func(){
        var in  string
        var in1  string

        for {
               fmt.Scanf("%s %s",&in,&in1)
              // fmt.Println(in,"  ok",in1)
               if in == "exit" {
		    //fmt.Println("exit")
                    onCansel()
		    return
               }
        }


  }() 


  

  select {
      case <- ctx.Done():
          fmt.Println("time.Second exit")

  }

}


